//
//  HomeViewController.m
//  MagicCube
//
//  Created by 蓓蕾 on 2022/2/18.
//

#import "HomeViewController.h"
#import "ClassRoomViewController.h"
#import "ViewController.h"

@interface HomeViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    [self getDataSource];
    [self initTableView];
}

-(void)getDataSource
{
    
    _dataArr = [NSMutableArray new];
    [_dataArr addObject:@"三阶魔方"];
    [_dataArr addObject:@"魔方课堂"];
}

-(void)initTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (indexPath.row < _dataArr.count) {
        NSString *videoPath = _dataArr[indexPath.row];
        NSString *videoName = [videoPath stringByDeletingPathExtension];
        videoName = [videoName lastPathComponent];
        cell.textLabel.text = videoName;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *itemName = _dataArr[indexPath.row];
    if ([itemName isEqualToString:@"三阶魔方"]) {
        ViewController *classroomVC = [[ViewController alloc] init];
        classroomVC.navigationItem.title = @"三阶魔方教程";
        [self.navigationController pushViewController:classroomVC animated:YES];
    }
    else
    {
        ClassRoomViewController *classroomVC = [[ClassRoomViewController alloc] init];
        classroomVC.navigationItem.title = @"魔方课堂";
        [self.navigationController pushViewController:classroomVC animated:YES];
    }
//    NSString *videoName = [videoPath stringByDeletingPathExtension];
//    videoName = [videoName lastPathComponent];
    
//    videoVC.videoPath = videoPath;
//    videoVC.videoName = videoName;
//    videoVC.videoID = indexPath.row + 1;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
